import config from 'config'
import httpFetch from 'share/httpFetch'
const url = `${config.baseUrl}/ledger`;

function urlJoin(params) {
  let res = [];
  for(let key in params){
    res.push(`${key}=${params[key]}`)
  }
  return res.join('&');
}

export default {

  //业务接口定义--获取列表
  getInterfaceList(params){
    return httpFetch.get(`${url}/api/function/query/by/page?${urlJoin(params)}`);
  },

  //业务接口定义--新建
  addInterface(params,userOID){
    return httpFetch.post(`${url}/api/function?operatorOid=${userOID}`,params);
  },

  //业务接口定义--编辑
  updateInterface(params,userOID){
    return httpFetch.put(`${url}/api/function?operatorOid=${userOID}`,params);
  },

  //业务接口定义--初始化
  initAll(params){
    return httpFetch.post(`${url}/api/function/init/all`,params);
  },


  //初始化按钮判断是否拥有
  judgeInit(setOfBooksId){
    return httpFetch.get(`${url}/api/function/has/inited?setOfBooksId=${setOfBooksId}`)
  },

  //场景定义--获取列表
  getSceneList(params){
    return httpFetch.get(`${url}/api/scene/define/query/by/page?${urlJoin(params)}`);
  },

  //场景定义--新建
  addScene(params,userOID){
    return httpFetch.post(`${url}/api/scene/define?operatorOid=${userOID}`,params);
  },

  //场景定义--编辑
  updateScene(params,userOID){
    return httpFetch.put(`${url}/api/scene/define?operatorOid=${userOID}`,params);
  },

  //核算要素--获取列表
  getElementList(params){
    return httpFetch.get(`${url}/api/scene/element/query/by/page?${urlJoin(params)}`);
  },

  //核算要素--新建
  addElement(params,userOID){
    return httpFetch.post(`${url}/api/scene/element?operatorOid=${userOID}`,params);
  },

  //核算要素--编辑
  updateElement(params,userOID){
    return httpFetch.put(`${url}/api/scene/element?operatorOid=${userOID}`,params);
  },

  //映射关系设置--获取列表
  getMappingList(params){
    return httpFetch.get(`${url}/api/element/segment/query/by/page?${urlJoin(params)}`);
  },

  //映射关系设置--删除关联
  deleteMapping(ids){
    return httpFetch.delete(`${url}/api/element/segment?ids=${ids}`);
  },

  //映射关系设置--添加
  addMapping(params,userOID){
    return httpFetch.post(`${url}/api/element/segment?operatorOid=${userOID}`,params)
  },

  //指定核算业务--获取列表
  getBusinessList(params){
    return httpFetch.get(`${url}/api/functionDef/query/pages/by/sceneDefId?${urlJoin(params)}`);
  },

  //核算业务类型--获取列表
  getTypeList(params){
    return httpFetch.get(`${url}/api/functionDef/query/by/page?${urlJoin(params)}`);
  },

  //核算业务类型--新增
  addType(params,userOID){
    return httpFetch.post(`${url}/api/functionDef?operatorOid=${userOID}`,params);
  },

  //核算业务类型--更新
  updateType(params,userOID){
    return httpFetch.put(`${url}/api/functionDef?operatorOid=${userOID}`,params);
  },

  //核算业务类型详情定义--获取列表
  getTypeDetailList(params){
    return httpFetch.get(`${url}/api/function/source/group/query/by/page?${urlJoin(params)}`);
  },

  //核算业务类型详情定义--新增
  addTypeDetail(params,userOID){
    return httpFetch.post(`${url}/api/function/source/group?operatorOid=${userOID}`,params);
  },

  //核算业务类型详情定义--更新
  updateTypeDetail(params,userOID){
    return httpFetch.put(`${url}/api/function/source/group?operatorOid=${userOID}`,params);
  },

  //来源数据详情--获取列表
  getDataList(params){
    return httpFetch.get(`${url}/api/function/segment/query/by/page?${urlJoin(params)}`);
  },

  // 来源数据详情--新建按钮是否展示
  dataCanAdd(params){
    return httpFetch.get(`${url}/api/function/source/group/is/possible/create/new/one?${urlJoin(params)}`);
  },

  //来源数据详情--新增
  addData(params,userOID){
    return httpFetch.post(`${url}/api/function/segment?operatorOid=${userOID}`,params);
  },

  //来源数据详情--更新
  updateData(params,userOID){
    return httpFetch.put(`${url}/api/function/segment?operatorOid=${userOID}`,params);
  },

  //借贷定义--获取列表
  getDebitList(params){
    return httpFetch.get(`${url}/api/dc/define/query/by/page?${urlJoin(params)}`);
  },

  //借贷定义--新增
  addDebit(params,userOID){
    return httpFetch.post(`${url}/api/dc/define?operatorOid=${userOID}`,params);
  },

  //借贷定义--更新
  updateDebit(params,userOID){
    return httpFetch.put(`${url}/api/dc/define?operatorOid=${userOID}`,params);
  },

  //借贷定义详情--获取列表
  getDebitDetailList(params){
    return httpFetch.get(`${url}/api/dc/define/detail/query/by/page?${urlJoin(params)}`);
  },

  //借贷定义详情--删除
  deleteDebitDetail(id){
    return httpFetch.delete(`${url}/api/dc/define/detail?id=${id}`);
  },

  //借贷定义详情--新增
  addDebitDetail(params,userOID){
    return httpFetch.post(`${url}/api/dc/define/detail?operatorOid=${userOID}`,params);
  },

  //借贷定义详情--更新
  updateDebitDetail(params,userOID){
    return httpFetch.put(`${url}/api/dc/define/detail?operatorOid=${userOID}`,params);
  },

  //匹配组定义--获取列表
  getMateList(params){
    return httpFetch.post(`${url}/api/ledScene/sceneMappingGroup/select`,params);
  },

  //匹配组定义--新增
  addMate(params){
    return httpFetch.post(`${url}/api/ledScene/sceneMappingGroup/create`,params);
  },

  //匹配组定义--编辑
  updateMate(params){
    return httpFetch.post(`${url}/api/ledScene/sceneMappingGroup/update`,params);
  },

  //科目映射--获取列表
  getObjectList(params){
    return httpFetch.post(`${url}/api/ledScene/accountingMap/query/by/page`, params);
  },

  //科目映射--新增/编辑
  addObject(params){
    return httpFetch.post(`${url}/api/ledScene/accountingMap/save`,params);
  },

  //科目映射--获取直列表
  getValueList(tenantId,setOfBooksId,id){
    return httpFetch.get(`${config.baseUrl}/api/open/ledger/element/value/group?tenantId=${tenantId}&setOfBooksId=${setOfBooksId}&types=${id}`);
  },

  //科目映射--删除科目
  deleteObject(params){
    return httpFetch.delete(`${url}/api/ledScene/accountingMap/delete`,params);
  },

  //系统映射字段查询
  getSystemMappingList(){
    return httpFetch.get(`${url}/api/scene/element/query/system/field`)
  },

  //指定核算业务--添加
  addSceneDetail(params,userOID){
    return httpFetch.post(`${url}/api/scene/function/define/ref?operatorOid=${userOID}`,params);
  },

  //指定核算业务--删除
  deleteSceneDetail(ids){
    return httpFetch.delete(`${url}/api/scene/function/define/ref?ids=${ids}`);
  },

  getRelativeList(params){
    return httpFetch.get(`${url}/api/scene/function/define/detail/query/by/page`,params)
  },

  saveRelativeList(params, operatorOid){
    return httpFetch.post(`${url}/api/scene/function/define/detail/save?operatorOid=${operatorOid}`,params)
  },

  //规则定义 -- 获取列表
  getRuleList(params){
    return httpFetch.get(`${url}/api/rule/define/query/by/page?${urlJoin(params)}`)
  },

  addRule(params,userOID){
    return httpFetch.post(`${url}/api/rule/define?operatorOid=${userOID}`,params);
  },

  updateRule(params,userOID){
    return httpFetch.put(`${url}/api/rule/define?operatorOid=${userOID}`,params);
  },

  //基础信息 -- 获取列表
  getBasisList(params){
    return httpFetch.get(`${url}/api/source/data/group/query/by/pages`,params);
  },

  viewBasisInfo(params){
    return httpFetch.get(`${url}/api/source/data/dict/query/list`,params);
  },

  // 关联基础信息
  getRelativeBasis(params){
    return httpFetch.post(`${url}/api/function/segment/extend/basic/data`, params);
  },

  cancelRelative(params){
    return httpFetch.post(`${url}/api/function/segment/cancel/basic/data`, params);
  }

}
